<html lang="en">
<head>
    <title>热点关注</title>
    <#include "../common/header.ftl">
    <script>
        $(function () {

            //点击模态框,回显攻略
            $("#btn_add").click(function () {
                var strategyId = $("#strategyId").val();
                var strategyTitle = $("#strategyId option:selected").html();

                if(strategyId == -1){
                    $.messager.confirm("温馨提示", "请先选中一个攻略");
                    return;
                }
                $("#editForm input[name='strategyTitle']").val(strategyTitle);
                $("#editForm input[name='strategyId']").val(strategyId);

                //回显关联游记
                var html = "";
                var travelsId = [];
                //下拉框去重
                $.get("/strategy/travelList.do",{strategyId:strategyId},function (data) {
                    $.each(data,function (index, item) {
                        travelsId.push(item.id);
                    });

                    $.get("/travel/getRegionTravelByStrategyId.do",{strategyId:strategyId},function (data) {


                        $.each(data,function (index, item) {
                            var inArray = $.inArray(item.id,travelsId);
                            if (inArray<0){
                                html += "<option value='"+item.id+"'>"+item.title+"</option>";
                            }
                        });
                        $("#travelSelect").html(html);

                        $("#editModal").modal("show");
                    });
                })


            });
            $(".submitBtn").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        window.location.reload();
                    }else(
                            $.messager.confirm("温馨提示","修改出错")
                    )
                })
            });
        });
    </script>
</head>
<body>
<!--左侧菜单回显变量设置-->
<#assign currentMenu="strategy_look">
<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">热点关注</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategy/lookList.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <label for="">攻略搜索:</label>
                <div class="form-group">
                    <select class="form-control" id="strategyId" name="strategyId">
                        <option value="-1">--请选择--</option>
                         <#list strategies as s>
                        <option value="${s.id}">${s.title}</option>
                         </#list>
                    </select>
                    <script>
                        $("#strategyId").val(${strategyId!})
                    </script>
                </div>
                <button id="btn_query" class="btn btn-success"><span class="glyphicon glyphicon-search"></span> 查询</button>
                <button type="button" id="btn_add" class="btn btn-info changeBtn"><span class="glyphicon glyphicon-plus"></span> 添加关联游记</button>
            </form>

            <table class="table table-striped table-hover" >
                <thead>
                    <tr>
                        <th>关联游记</th>
                    </tr>
                </thead>
                <#list list as entity>
                   <tr>
                       <td>${entity.id!}</td>
                       <td>${entity.title!}</td>
                       <td><a href="/travel/releaseList.do?travelId=${entity.id}" target="_blank">查看游记文章</a></td>
                       <td>
                        <a href="/strategy/deleteRelation.do?travelId=${entity.id}&strategyId=${strategyId}" class="btn changeBtn">删除</a>
                       </td>
                   </tr>
               </#list>
            </table>
        </div>
    </div>
</div>


<!---攻略分类编辑--->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/添加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategy/insertRelation.do" method="post" id="editForm">
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">攻略：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="strategyTitle" value=""  readonly>
                            <input type="hidden" class="form-control" name="strategyId" value="" >
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">关联游记：</label>
                        <div class="col-sm-6">
                            <select id="travelSelect" name="travelId" class="form-control " >
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary submitBtn">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>